﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StorageRenew.aspx.cs" Inherits="Web.User.Storage.StorageRenew" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../../Scripts/WebInner.js" type="text/javascript"></script>
    <script src="../../Scripts/Common.js" type="text/javascript"></script>
    <link href="../../Styles/Common.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Zebra/zebra_dialog.js" type="text/javascript"></script>
    <link href="../../Scripts/Zebra/zebra_dialog.css" rel="stylesheet" type="text/css" />
    <script src="../../Lodop6.198/LodopFuncs.js" type="text/javascript"></script>
      <script type="text/javascript">
          /*--------窗体启动设置和基本设置--------*/
          /*--loadFuntion--*/
          $(function () {

              var Dep_SID = getQueryString("Dep_SID");
              if (Dep_SID != "") {
                  $('input[name=txtDep_SID]').val(Dep_SID);
                  $('#Interest').fadeIn('normal'); //显示兑换信息选择项
                  InitStorageInfo(Dep_SID);
                  InitDepositor(Dep_SID);
                  GetInterestState(Dep_SID);
              }

              $('select[name=TypeID]').change(function () {
                  InitTimeID();
                  $('input[name=txtTypeID]').val($('select[name=TypeID] option:selected').val());
              });
              $('select[name=TimeID]').change(function () {
                  InitTimeID();
                  $('input[name=txtTimeID]').val($('select[name=TimeID] option:selected').val());
              });


              var now = new Date(); //获取系统日期，即Sat Jul 29 08:24:48 UTC+0800 2006 
              var yy = now.getFullYear(); //截取年，即2006 
              var mo = now.getMonth() + 1; //截取月，即07 
              var dd = now.getDate(); //截取日，即29 
              //取时间 
              var hh = now.getHours(); //截取小时，即8 
              var mm = now.getMinutes(); //截取分钟，即34 
              var ss = now.getSeconds(); //获取秒 
              $('input[name=dt_Interest]').val(yy + '-' + mo + '-' + dd + ' ' + hh + ':' + mm + ':' + ss);
          });


          //获取储户类型
          function InitTypeID() {
              var VarietyID = $('input[name=txtVarietyID]').val();
              $('select[name=TypeID]').empty();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetUserTypeByVarietyID&VarietyID=' + VarietyID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      for (var i = 0; i < r.length; i++) {
                          $('select[name=TypeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }
                      InitTimeID(); //获取存期信息
                  }, error: function (r) {
                      if (r.responseText != 'Error') {
                          $.Zebra_Dialog('<strong>不存在此储户类型,您可以请管理员添加相关的基础数据信息 ！</strong>');
                      }
                  }
              });
          }

          //获取存期信息
          function InitTimeID() {
              var VarietyID = $('input[name=txtVarietyID]').val();
              var TypeID = $('select[name=TypeID] option:selected').val();
              $('select[name=TimeID]').empty();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetTimeByVUID&VarietyID=' + VarietyID + '&TypeID=' + TypeID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      for (var i = 0; i < r.length; i++) {
                          $('select[name=TimeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }
                    
                  }, error: function (r) {
                      if (r.responseText != 'Error') {
                          $.Zebra_Dialog('<strong>加载储户存期失败 ！</strong>');
                      }
                  }
              });
          }


          function GetInterestState(Dep_SID) {
              $.ajax({
                  url: '/User/Exchange/exchange.ashx?type=GetInterestState&ID=' + Dep_SID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                    
                      var Interest = r[0].Interest;
                      if (parseFloat(Interest) < 0) {
                          $('#btnAdd').attr('disabled', 'disabled');
                          $('input[name=numInterest]').val('0');
                          $('#spanMsg').html('您的存储产品未到期，不能转存');
                      } else {
                          $('#btnAdd').removeAttr('disabled');
                          $('input[name=numInterest]').val(Interest);
                          $('#spanMsg').html('');
                      }

                      var ISJiexi = r[0].ISJiexi; //是否允许仅结息
                      if (ISJiexi == "1") {
                          $("input[name='InterestType'][value='1']").removeAttr("disabled");
                      }
                      else {
                          $("input[name='InterestType'][value='1']").attr('disabled', 'disabled');
                      }

                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载储户存储信息失败 ！</strong>');
                  }
              });
          }

          function InitStorageInfo(Dep_SID) {
              $.ajax({
                  url: '/User/Exchange/exchange.ashx?type=GetStorageInfoByID&ID=' + Dep_SID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      $('#StorageList').hide();
                      $('#Storage').show();
                      $('#depositorInfo').show();
                      $('input[name=txtVarietyID]').val(r[0].txtVarietyID); //商品ID
                      $('#VarietyID').html(r[0].VarietyID);
                      $('#StorageNumber').html(r[0].StorageNumber);
                      $('#StorageDate').html(r[0].StorageDate);
                      $('#Price_ShiChang').html(r[0].Price_ShiChang);
                      $('#TimeID').html(r[0].TimeID);
                      $('#numDate').html(r[0].numDate);

                      $('input[name=txtTypeID]').val(r[0].txtTypeID);
                      var txtTypeID = r[0].txtTypeID;
                      var txtTimeID = r[0].txtTimeID;

                      /*--------加载转存类型--------*/
                      var VarietyID = $('input[name=txtVarietyID]').val();
                      $('select[name=TypeID]').empty();
                      $.ajax({
                          url: '/User/Storage/storage.ashx?type=GetUserTypeByVarietyID&VarietyID=' + VarietyID,
                          type: 'post',
                          data: '',
                          dataType: 'json',
                          success: function (r) {
                              for (var i = 0; i < r.length; i++) {
                                  $('select[name=TypeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                              }

                              $('select[name=TypeID]').val(txtTypeID);
                      
                          }, error: function (r) {
                              if (r.responseText != 'Error') {
                                  $.Zebra_Dialog('<strong>不存在此储户类型,您可以请管理员添加相关的基础数据信息 ！</strong>');
                              }
                          }
                      });
                      /*--------End加载转存类型--------*/


                      /*--------加载存期类型--------*/
                      var TypeID = r[0].txtTypeID;
                   
                      $('select[name=TimeID]').empty();
                      $.ajax({
                          url: '/User/Storage/storage.ashx?type=GetTimeByVUID&VarietyID=' + VarietyID + '&TypeID=' + TypeID,
                          type: 'post',
                          data: '',
                          dataType: 'json',
                          success: function (r) {
                              for (var i = 0; i < r.length; i++) {
                                  $('select[name=TimeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                              }
                              $('select[name=TimeID]').val(txtTimeID);
                              $('input[name=txtTimeID]').val(txtTimeID);
                          }, error: function (r) {
                              if (r.responseText != 'Error') {
                                  $.Zebra_Dialog('<strong>加载储户存期失败 ！</strong>');
                              }
                          }
                      });
                      /*--------End 加载存期类型--------*/

                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载储户存储信息失败 ！</strong>');
                  }
              });
          }




          function InitDepositor(Dep_SID) {
              $.ajax({
                  url: '/User/Exchange/exchange.ashx?type=GetDepInfoByStorageID&ID=' + Dep_SID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      $('#StorageList').hide();
                      $('#Storage').show();
                      $('#depositorInfo').show();
                      $('#QAccountNumber').val(r[0].AccountNumber);

                      $('#D_AccountNumber').html(r[0].AccountNumber);
                      $('#D_strName').html(r[0].strName);
                      $('input[name=Dep_Name]').val(r[0].strName);
                      $('#D_PhoneNo').html(r[0].PhoneNO);
                      $('#D_strAddress').html(r[0].strAddress);
                      $('#D_numState').html(r[0].numState);
                      $('#D_IDCard').html(r[0].IDCard);

                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载储户存储信息失败 ！</strong>');
                  }
              });
          }




          function frmSubmit() {

              if ($('input[name=txtInterestType]').val() == "") {
                  $.Zebra_Dialog('<strong>请设置转存类型！</strong>');
                  return false;
              }
              $.ajax({
                  url: '/Ashx/exchangeprop.ashx?type=JieXi',
                  type: 'post',
                  data: $('#form1').serialize(),
                  dataType: 'text',
                  success: function (r) {
                      if (r.responseText != "Error") {

                          $.Zebra_Dialog('<strong>结息成功，请打印存折 ！</strong>');
                          $('#Query').fadeOut(); //隐藏查询按钮

                          $('#btnAdd').attr('disabled', 'disabled');
                          $('#btnAdd').css('background', '#aaa');
                          $('#btnCunZhe').removeAttr('disabled');
                      }
                   
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>兑换商品失败 ！</strong>');
                  }
              });
          }


          /*--ENd loadFuntion--*/

          function ChangeType(type) {
              $('input[name=txtInterestType]').val(type);
           
              if (type == "1") {//仅结息
                  $('#trTime').fadeOut("fast");
                  //计算利息
              }
              else if (type == "2") {//结息后转存
                  $('#trTime').fadeIn("fast");
              } else { //不结息直接转存
                  $('#trTime').fadeOut("fast");
              }
          }



          /*--------End 数据增删改操作--------*/

          var p_left = 0; var p_ltop = 0; var p_lwidth = 0; var p_lheight = 0;
          $(function () {
              $.ajax({
                  url: '/Ashx/wbinfo.ashx?type=GetPrintSetting_Dep',
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      p_lwidth = r[0].Width;
                      p_lheight = r[0].Height;
                      p_lleft = r[0].DriftRateX;
                      p_ltop = r[0].DriftRateY;
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载打印坐标时出现错误 ！</strong>');
                  }
              });
          });
          function CreateOneFormPage() {
              LODOP = getLodop();
              LODOP.PRINT_INIT("存折打印");
              LODOP.SET_PRINT_STYLE("FontSize", 18);
              LODOP.SET_PRINT_STYLE("Bold", 1);
              LODOP.ADD_PRINT_TEXT(0, 0, 0, 0, "打印页面部分内容");
              LODOP.ADD_PRINT_HTM(p_ltop, p_lleft, p_lwidth, p_lheight, document.getElementById("divPrint").innerHTML);

          };


          //加载新的业务编号
          function InitBusinessNO() {
              $.ajax({
                  url: "/User/Storage/storage.ashx?type=GetNewBusinessNO&AccountNumber=" + $('#D_AccountNumber').html(),
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('input[name=BusinessNO]').val(r);

                      frmSubmit();
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载信息失败 ！</strong>');
                  }
              });
          }



          function PrintCunZhe() {

              $.ajax({
                  url: '/Ashx/storage.ashx?type=PrintDep_OperateLog&BusinessNO=' + $('input[name=BusinessNO]').val() + '&AccountNumber=' + $('#D_AccountNumber').html(),
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('#divPrint').html('');
                      $('#divPrint').append(r);
                      CreateOneFormPage();
                      LODOP.PREVIEW(); //打印存折
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载打印坐标时出现错误 ！</strong>');
                  }
              });
          }

      </script>
</head>
<body>
    <div id="divPrint" style="display:none">

    </div>

    <form id="form1" runat="server">
    <div class="pageHead">
        <b>结息</b><%--<span id="spanHelp" style="cursor: pointer">帮助</span>--%>
    </div>
    <div id="divHelp"  class="pageHelp">
<span>提示1：业务进行顺序：第一步：输入储户账号-->第二步：选择业务类型-->第三步：再选择交易商品-->第四步：输入数量-->添加，即完成一笔业务。
完成后，单击“结账”，完成商品兑换。</span><br />
<span>提示2：定期储粮兑换成品粮时，到期按到期价兑换，不到期按约定比例享受按到期价 优惠兑换 ，超过优惠额度则按存入价兑换；其它类型储户按约定计息（或不计息）兑换。</span><br />
<span>提示3：兑换时请注意兑换的计量单位与价格。</span><br />
</div>
<div id="storageQuery">

</div>
    <div style="margin: 20px 0px;">
        <div id="Query">
            <span>储户账号:</span>
            <input type="text" id="QAccountNumber" style="font-size:16px; font-weight:bolder;" runat="server" />
           &nbsp; <span>密码:</span>
            <input type="password" id="QPassword" style="font-size:12px;  width:100px;" runat="server" />
            <asp:ImageButton ID="ImageButton1" ImageUrl="~/images/seach_brown.png" 
                runat="server" onclick="ImageButton1_Click" />
        </div>
           <div id="depositorInfo" runat="server"  style="display:none;">
            <table class="tabData"  style="margin:20px 0px;">
                <tr >
                    <td colspan="6" style="border-bottom:1px solid #aaa; height:25px; text-align:center">
                        <span style="font-size: 16px; font-weight: bolder; color:Green">储户基本信息</span>
                    </td>
                </tr>
                <tr>
                    <th align="center" style="width:100px; height:30px;">
                        储户账号
                    </th>
                    <th align="center" style="width:100px;">
                        储户姓名
                    </th>
                     <th align="center" style="width:100px;">
                        移动电话
                    </th>
                      <th align="center" style="width:100px;">
                        当前状态
                    </th>
                      <th align="center" style="width:150px;">
                        身份证号
                    </th>
                     <th align="center" style="width:200px;">
                        储户地址
                    </th>
                   
                </tr>
                   <tr>
                  
                    <td style="height:30px;">
                        <span style="font-weight:bolder; color:Blue;" id="D_AccountNumber"   runat="server"></span>
                    </td>
                    
                    <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_strName" runat="server"></span>
                    </td>
                    <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_PhoneNo" runat="server"></span>
                    </td>
                     <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_numState" runat="server"></span>
                    </td>
                      <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_IDCard" runat="server"></span>
                    </td>
                    <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_strAddress" runat="server"></span>
                    </td>
                </tr>
            </table>
        </div>
        <div id="StorageList" runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table class="tabData" >
                    <tr class="tr_head">
                        <th style="width: 100px; height:20px; text-align: center;">
                            存贷产品
                        </th>
                        <th style="width: 80px; text-align: center;">
                            结存数量
                        </th>
                        <th style="width: 100px; text-align: center;">
                            存入时间
                        </th>
                        <th style="width: 80px; text-align: center;">
                            存入价
                        </th>
                        <th style="width: 80px; text-align: center;">
                            存期
                        </th>
                        <th style="width: 80px; text-align: center;">
                            天数
                        </th>
                        <th style="width: 80px; text-align: center;">
                            活期利率
                        </th>
                        <th style="width: 100px; text-align: center;">
                            利息
                        </th>
                        <th style="width: 160px; text-align: center;">
                            结算类型
                        </th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr style='background-color: <%#(Container.ItemIndex%2==0)?"#FFFFF;":"#fcf3f4"%>'
                    onmouseover="change_colorOver(this)" onmouseout="change_colorOut(this)">
                    <td style="height:25px;">
                        <%#Eval("VarietyID")%>
                    </td>
                    <td>
                        <%#Eval("StorageNumber")%>
                    </td>
                    <td>
                        <%#Eval("StorageDate")%>
                    </td>
                    <td>
                        <%#Eval("Price_ShiChang")%>
                    </td>
                    <td>
                        <%#Eval("TimeID")%>
                    </td>
                    <td>
                        <%#Web.common.GetDay(Eval("StorageDate"))%>
                    </td>
                    <td>
                        <%#Eval("CurrentRate")%>
                    </td>
                    <td>
                        <%#Web.common.GetLiXi(Eval("ID"))%>
                    </td>
                    <td>
                       <a href="/User/Exchange/ExchangeGoods.aspx?Dep_SID=<%#Eval("ID") %>">兑换</a>&nbsp;
                    <a href="/User/Exchange/StoreToSell.aspx?Dep_SID=<%#Eval("ID") %>">存转销</a>&nbsp;
                       <a href="/User/Storage/StorageRenew.aspx?Dep_SID=<%#Eval("ID") %>">结息</a>
                       
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
            <tr>
            <td colspan="2">
            <span style="font-weight:bolder">折合现金合计:</span>
            </td>
            <td colspan="6" style="text-align:center">
            <span id="spanTotal" runat="server" style="color:Red; font-size:16px">￥<%=Web.common.numTotol%></span>
          
            </td>
            </tr>
                <!--底部模板-->
                </table>
                <!--表格结束部分-->
            </FooterTemplate>
        </asp:Repeater>
        </div>
        <div id="Storage" style="display:none;">
          <table class="tabData" style="margin:20px 0px;">
          <tr>
          <td colspan="6" style="font-weight:bolder; height:25px; color:Green; font-size:16px; border-bottom:1px solid #888;">存储信息</td>
          </tr>
                    <tr class="tr_head">
                        <th style="width: 200px; height:30px; text-align: center;">
                            存储产品
                        </th>
                        <th style="width: 110px; text-align: center;">
                            结存数量
                        </th>
                        <th style="width: 110px; text-align: center;">
                            存入时间
                        </th>
                        <th style="width: 110px; text-align: center;">
                            存入价
                        </th>
                        <th style="width: 110px; text-align: center;">
                            存期
                        </th>
                        <th style="width: 110px; text-align: center;">
                            天数
                        </th>
                    </tr>
                    <tr>
                     <td style="height:30px;"><span id="VarietyID" style="font-weight:bolder; color:Blue; padding:5px 0px;"></span></td>
                     <td><span id="StorageNumber" style="font-weight:bolder; color:Blue; padding:5px 0px;"></span></td>
                      <td><span id="StorageDate" style="font-weight:bolder; color:Blue; padding:5px 0px;"></span></td>
                       <td><span id="Price_ShiChang" style="font-weight:bolder; color:Blue; padding:5px 0px;"></span></td>
                        <td><span id="TimeID" style="font-weight:bolder; color:Blue; padding:5px 0px;"></span></td>
                         <td><span id="numDate" style="font-weight:bolder; color:Blue; padding:5px 0px;"></span></td>
                    </tr>
                    </table>
           
        </div>
        <div id="Interest" class="pageEidtInner"  style="display:none;border-radius:20px; padding:20px;">
        <table >
            <tr>
                <td align="right" style="width: 120px; height:30px;">
                    续存选项
                </td>
                <td>
                    <input type="radio" name="InterestType" value="1" onclick="ChangeType(1)" />仅结息&nbsp;
                    <input type="radio" name="InterestType" value="2" onclick="ChangeType(2)" />结息后转存&nbsp;
                    <input type="radio" name="InterestType" value="3" onclick="ChangeType(3)" />不结息直接转存&nbsp;
                </td>
            </tr>
             <tr id="trTime" style="display:none;">
                <td align="right" style="height:30px;">
                    转存类型
                </td>
                <td>
                   <select name="TypeID" style="width:100px;" ></select> &nbsp;
                 <span>存期:</span>
                 <select name="TimeID" style="width:100px"></select>
                </td>
            </tr>
              <tr>
                  <td align="right" style="height:30px;">
                    利息
                </td>
                <td>
                    <input type="text"  readonly="readonly" style="background-color:#ddd;" name="numInterest" value="" />
                  
                </td>
            </tr>
              <tr>
                  <td align="right" style="height:30px;">
                    续存日期
                </td>
                <td>
                    <input type="text" disabled="disabled" name="dt_Interest" value="" />
                  
                </td>
            </tr>
            <tr>
            <td></td>

            <td style="height:40px; ">
               <input type="button"  id="btnAdd" value="保存数据" runat="server" onclick="InitBusinessNO();" />&nbsp;&nbsp;
      
                              <input type="button" id="btnCunZhe"  value="打印存折" disabled="disabled" onclick="PrintCunZhe()" />
            </td>
            </tr>
            <tr>
            <td></td>

            <td style="height:20px; ">
             <span id="spanMsg" style="color:Red;  font-weight:bolder;"></span>
            </td>
            </tr>
            </table>
            </div>
         
    </div>
    
    <div  style="display:none;">
    <%--业务编号--%>
      <input type="text"  name="BusinessNO" value="" />
     
       <%--储户姓名--%>
      <input type="text" name="Dep_Name" />
      <%--存储编号--%>
     <input type="text" name="txtDep_SID" />

     <input type="text" name="txtVarietyID" />
     <input type="text" name="txtTypeID" />
     <input type="text" name="txtTimeID" />


     <input type="text" name="txtInterestType" />
    </div>
    </form>
    
    <%--定义编号--%>
    <input type="hidden" id="WBID" value="" />
    <%--定义背景色的隐藏域--%>
    <input type="hidden" id="colorName" value="" />
</body>
</html>

